package com.lt.test.provider.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.lt.test.api.AttendnService;
import com.lt.test.entity.DTO.ResponseDTO;
import com.lt.test.provider.mapper.AttendnMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service(version = "1.0.0")
public class AttendnServiceImpl implements AttendnService{
	private static Logger log = LoggerFactory.getLogger(AttendnServiceImpl.class);
    @Resource
    AttendnMapper attendnMapper;
    
	@Override
	public List<Map<String, Object>> getShopStaff(Map parameter) {
		return attendnMapper.getShopStaff(parameter);
	}



	@Override
	public List<Map<String, Object>> getShopUsersDutyList(Map parameter) {
		return attendnMapper.getShopUsersDutyList(parameter);
	}



	@Override
	public List<Map<String, Object>> getShopUserDutyList(Map parameter) {
		return attendnMapper.getShopUserDutyList(parameter);
	}

	@Override
	public Map<String, List<Map<String, Object>>> getshopstaffAndDutyUser(Map parameter) {
		Map<String, List<Map<String, Object>>> lMap = new HashMap<>();
		lMap.put("a", attendnMapper.getShopStaff(parameter));
		lMap.put("b", attendnMapper.getShopUserDutyList(parameter));
		lMap.put("c", attendnMapper.getShopDutySigninList(parameter));
		return lMap;
	}

	@Override
	public ResponseDTO insertShopUserDuty(Map parameter) {
		ResponseDTO responseDTO = new ResponseDTO();
		String code = responseDTO.getCode();
		String msg = responseDTO.getMessage();
		boolean success = responseDTO.getSuccess(); 
		String id = "S"+UUID.randomUUID().toString().replace("-", "").toUpperCase();
		parameter.put("id", id);
		if (parameter.get("userId") == null) {
			msg = "请选择员工";
		}
		if (parameter.get("shopId") == null) {
			msg = "请选择店铺";
		}
		if (parameter.get("dutyBeginTime") == null) {
			msg = "请填写上班时间";
		}
		if (parameter.get("dutyEndTime") == null) {
			msg = "请选择下班时间";
		}
		if (parameter.get("dutyDate") == null) {
			msg = "请选择值日日期";
		}
		try{
			attendnMapper.insertShopUserDuty(parameter);
			code = "200";
			msg = "添加成功";
			success = true;
			responseDTO.setData(id);
		}catch(Exception e){
			log.error(e.getMessage());
		}
		responseDTO.setCode(code);
		responseDTO.setSuccess(success);
		responseDTO.setMessage(msg);
		return responseDTO;
	}



	@Override
	public ResponseDTO updateShopUserDuty(Map parameter) {
		ResponseDTO responseDTO = new ResponseDTO();
		String code = responseDTO.getCode();
		String msg = responseDTO.getMessage();
		boolean success = responseDTO.getSuccess(); 
		if (parameter.get("id") == null) {
			msg = "请选择员工";
		}
		try{
			attendnMapper.updateShopUserDuty(parameter);
			code = "200";
			msg = "修改成功";
			success = true;
		}catch(Exception e){
			log.error(e.getMessage());
		}
		responseDTO.setCode(code);
		responseDTO.setSuccess(success);
		responseDTO.setMessage(msg);
		return responseDTO;
	}



	@Override
	public ResponseDTO deleteShopUserDutyById(String id) {
		ResponseDTO responseDTO = new ResponseDTO();
		String code = responseDTO.getCode();
		String msg = responseDTO.getMessage();
		boolean success = responseDTO.getSuccess(); 
		try{
			attendnMapper.deleteShopUserDutyById(id);
			msg = "删除成功";
			success = true;
		}catch(Exception e){
			log.error(e.getMessage());
		}
		responseDTO.setCode(code);
		responseDTO.setSuccess(success);
		responseDTO.setMessage(msg);
		return responseDTO;
	}



	@Override
	public Map<String, List<Map<String, Object>>> getshopSigninAndDutyUser(Map parameter) {
		Map<String, List<Map<String, Object>>> lMap = new HashMap<>();
		lMap.put("a", attendnMapper.getShopDutySigninList(parameter));
		lMap.put("b", attendnMapper.getShopUserDutyList(parameter));
		return lMap;
	}

}
